package com.lollipop.rabbitmq.seven;

import com.lollipop.rabbitmq.util.RabbitMqUtiils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;

/**
 * @Author: Lollipop
 * @Date: 2021-10-05 20:05
 * @Description:
 */
public class ReceiveLogsTopic01 {
    public static final String EXCHANGE_NAME = "topic_logs";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMqUtiils.getChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC);
        String queueName = "Q1";
        channel.queueDeclare(queueName, false, false, false, null);
        channel.queueBind(queueName, EXCHANGE_NAME, "*.orange.*");
        System.out.println("ReceiveLogsTopic01等待接收消息……");
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("消费者ReceiveLogsTopic01接收到的消息：" + new String(message.getBody(), StandardCharsets.UTF_8) + "routingkey:" + message.getEnvelope().getRoutingKey());
        };
        channel.basicConsume("disk", true, deliverCallback, consumerTag -> {
        });
    }
}
